
// 渲染主页面逻辑

import Header from '../../components/Header';
import LeftTree from '../../../../public/components/LeftTree';
import AddNewPage from '../../components/AddNewPage';
import MainTable from '../../components/MainTable';
import EmptyPage from '../../../../public/components/EmptyPage';

export default function renderPage() {
    const {
        humanResourceOrganizationValue,
        page,
        hasSearched,
        selectedRows,
        pageInfo,
        showTableCheckbox,
        addPageTemplate,
        pageFrom,
        include_child_depts,
        include_child_orgs,
        imageData,
        subTableEditable
    } = this.state;

    let color = getColor().color;
    let darkTheme = document.body.className.includes('c-lightapp-front-black');
    
    if (page === 'main' || page === 'adjust-sort') {
        return (
            <div className="main-page">
                <Header
                    {...this.props}
                    page={page}
                    ref={ref => this.headerRef = ref}
                    updateState={this.updateState}
                    humanResourceOrganizationValue={humanResourceOrganizationValue}
                    getMainTableData={this.getMainTableData}
                    hasSearched={hasSearched}
                    selectedRows={selectedRows}
                    getRef={this.getRef}
                    toEditPage={this.toEditPage}
                    deleteMainTableRow={this.deleteMainTableRow}
                    batchAddSub={this.batchAddSub}
                    include_child_depts={include_child_depts}
                    include_child_orgs={include_child_orgs}
                    goBackToMainPage={this.goBackToMainPage}
                    print={this.print}
                    fileManager={this.fileManager}
                    printOutput={this.printOutput}
                    setButtonStatus2={this.setButtonStatus2}
                />
                <div className="entry-mng-page-content">
                    <div 
                        className="left-content"
                        style={{
                            borderColor: darkTheme ? '#39393f' : '#d7d7d7'
                        }}
                    >
                        <LeftTree
                            treeType="orgRange"
                            asyncTree={this.props.asyncTree}
                            onSelect={this.selectTree}
                            pk_org={humanResourceOrganizationValue.refpk}
                            treeId="departmentTree"
                            MultiInit={this.props.MultiInit}
                        />
                    </div>
                    <div className="right-content">
                        {
                            humanResourceOrganizationValue.refpk ?
                            <MainTable
                                {...this.props}
                                updateState={this.updateState}
                                handleTableSelect={this.handleTableSelect}
                                getMainTableData={this.getMainTableData}
                                pageInfo={pageInfo}
                                showTableCheckbox={showTableCheckbox}
                                toEditPage={this.toEditPage}
                                selectAll={this.selectAll}
                                page={page}
                            /> :
                            <EmptyPage
                                emptyTips="暂无数据，请先选择人力组织"
                            />
                        }
                    </div>
                </div> 
                
            </div>
        );
    }
    else if (page === 'add-new') {
        return (
            <AddNewPage
                {...this.props}
                updateState={this.updateState}
                addPageTemplate={addPageTemplate}
                goBackToMainPage={this.goBackToMainPage}
                pageFrom={pageFrom}
                humanResourceOrganizationValue={humanResourceOrganizationValue}
                copyRow={this.copyRow}
                deleteRow={this.deleteRow}
                addRow={this.addRow}
                imageData={imageData}
                cancelEdit={this.cancelEdit}
                subTableEditable={subTableEditable}
                getModifyData={this.getModifyData}
                selectedRows={selectedRows}
                setButtonStatus2={this.setButtonStatus2}
            />
        );
    }
}
